home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / v_video.c < prev    next >
C/C++ Source or Header  |  1998-02-21  |  17KB  |  654 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    Gamma correction LUT stuff.
  21. //    Functions to draw patches (by post) directly to screen.
  22. //    Functions to blit a block to the screen.
  23. //
  24. //-----------------------------------------------------------------------------
  25.  
  26.  
  27. static const char
  28. rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $";
  29.  
  30.  
  31. #include "i_system.h"
  32. #include "i_video.h"
  33. #include "r_local.h"
  34.  
  35. #include "doomdef.h"
  36. #include "doomstat.h"
  37. #include "doomdata.h"
  38.  
  39. #include "m_bbox.h"
  40. #include "m_swap.h"
  41. #include "m_argv.h"
  42. #include "am_map.h"
  43. #include "r_draw.h"
  44.  
  45. #include "v_video.h"
  46.  
  47.  
  48. // Each screen is [SCREENWIDTH*SCREENHEIGHT]; 
  49. byte*                screens[5];    
  50.  
  51. int                dirtybox[4]; 
  52.  
  53.  
  54.  
  55. // Now where did these came from?
  56. byte gammatable[5][256] =
  57. {
  58.     {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
  59.      17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
  60.      33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
  61.      49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
  62.      65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
  63.      81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,
  64.      97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,
  65.      113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
  66.      128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  67.      144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  68.      160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  69.      176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  70.      192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  71.      208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  72.      224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  73.      240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255},
  74.  
  75.     {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31,
  76.      32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55,
  77.      56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77,
  78.      78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,
  79.      99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,
  80.      115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129,
  81.      130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,
  82.      146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160,
  83.      161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175,
  84.      175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189,
  85.      190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204,
  86.      205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218,
  87.      219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232,
  88.      233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246,
  89.      247,248,249,250,251,252,252,253,254,255},
  90.  
  91.     {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42,
  92.      43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69,
  93.      70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93,
  94.      94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112,
  95.      113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
  96.      129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144,
  97.      144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159,
  98.      160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173,
  99.      174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188,
  100.      188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201,
  101.      202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215,
  102.      216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228,
  103.      229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241,
  104.      242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254,
  105.      255},
  106.  
  107.     {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55,
  108.      57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85,
  109.      86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107,
  110.      108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,
  111.      125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140,
  112.      141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,
  113.      155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169,
  114.      169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182,
  115.      183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195,
  116.      195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207,
  117.      207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219,
  118.      219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230,
  119.      231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241,
  120.      242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252,
  121.      253,253,254,254,255},
  122.  
  123.     {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76,
  124.      78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106,
  125.      107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,
  126.      125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,
  127.      142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155,
  128.      156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169,
  129.      169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181,
  130.      182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193,
  131.      193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203,
  132.      204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214,
  133.      214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224,
  134.      224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233,
  135.      234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242,
  136.      243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,
  137.      251,252,252,253,254,254,255,255}
  138. };
  139.  
  140.  
  141.  
  142. int    usegamma;
  143.              
  144. //
  145. // V_MarkRect 
  146. // 
  147. /*
  148. void
  149. V_MarkRect
  150. ( int        x,
  151.   int        y,
  152.   int        width,
  153.   int        height ) 
  154.     M_AddToBox (dirtybox, x, y); 
  155.     M_AddToBox (dirtybox, x+width-1, y+height-1); 
  156. */
  157.  
  158.  
  159. //
  160. // V_CopyRect 
  161. // 
  162. void
  163. V_CopyRect
  164. ( int        srcx,
  165.   int        srcy,
  166.   int        srcscrn,
  167.   int        width,
  168.   int        height,
  169.   int        destx,
  170.   int        desty,
  171.   int        destscrn ) 
  172.     byte*    src;
  173.     byte*    dest; 
  174.      
  175. #ifdef RANGECHECK 
  176.     if (srcx<0
  177.     ||srcx+width >SCREENWIDTH
  178.     || srcy<0
  179.     || srcy+height>SCREENHEIGHT 
  180.     ||destx<0||destx+width >SCREENWIDTH
  181.     || desty<0
  182.     || desty+height>SCREENHEIGHT 
  183.     || (unsigned)srcscrn>4
  184.     || (unsigned)destscrn>4)
  185.     {
  186.     I_Error ("Bad V_CopyRect");
  187.     }
  188. #endif 
  189.     src = screens[srcscrn]+SCREENWIDTH*srcy+srcx; 
  190.     dest = screens[destscrn]+SCREENWIDTH*desty+destx; 
  191.  
  192.     for ( ; height>0 ; height--) 
  193.     { 
  194.     memcpy (dest, src, width); 
  195.     src += SCREENWIDTH; 
  196.     dest += SCREENWIDTH; 
  197.     } 
  198.  
  199.     if (destscrn == 0)
  200.         I_MarkRect (destx, desty, width, height);
  201.  
  202.  
  203. #ifndef AMIGA
  204. //
  205. // V_DrawPatch
  206. // Masks a column based masked pic to the screen. 
  207. //
  208. void
  209. V_DrawPatch
  210. ( int        x,
  211.   int        y,
  212.   int        scrn,
  213.   patch_t*    patch ) 
  214.  
  215.     int        count;
  216.     int        col; 
  217.     column_t*    column; 
  218.     byte*    desttop;
  219.     byte*    dest;
  220.     byte*    source; 
  221.     int        w; 
  222.     int        x0;
  223.      
  224.     y -= SWAPSHORT(patch->topoffset); 
  225.     x -= SWAPSHORT(patch->leftoffset); 
  226. #ifdef RANGECHECK 
  227.     if (x<0
  228.     ||x+SWAPSHORT(patch->width) >SCREENWIDTH
  229.     || y<0
  230.     || y+SWAPSHORT(patch->height)>SCREENHEIGHT 
  231.     || (unsigned)scrn>4)
  232.     {
  233.       fprintf( stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  234.       // No I_Error abort - what is up with TNT.WAD?
  235.       fprintf( stderr, "V_DrawPatch: bad patch (ignored)\n");
  236.       return;
  237.     }
  238. #endif 
  239.  
  240.     x0 = x;
  241.     col = 0; 
  242.     desttop = screens[scrn]+y*SCREENWIDTH+x; 
  243.      
  244.     w = SWAPSHORT(patch->width); 
  245.  
  246.     for ( ; col<w ; x++, col++, desttop++)
  247.     { 
  248.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[col])); 
  249.  
  250.     // step through the posts in a column 
  251.     while (column->topdelta != 0xff ) 
  252.     { 
  253.         source = (byte *)column + 3; 
  254.         dest = desttop + column->topdelta*SCREENWIDTH; 
  255.         count = column->length; 
  256.              
  257.         while (count--) 
  258.         { 
  259.         *dest = *source++; 
  260.         dest += SCREENWIDTH; 
  261.         } 
  262.         column = (column_t *)(  (byte *)column + column->length 
  263.                     + 4 ); 
  264.     } 
  265.     }             
  266.     if (scrn == 0)
  267.     I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height));
  268. #endif
  269.  
  270. //
  271. // V_DrawPatchFlipped 
  272. // Masks a column based masked pic to the screen.
  273. // Flips horizontally, e.g. to mirror face.
  274. //
  275. void
  276. V_DrawPatchFlipped
  277. ( int        x,
  278.   int        y,
  279.   int        scrn,
  280.   patch_t*    patch ) 
  281.  
  282.     int        count;
  283.     int        col; 
  284.     column_t*    column; 
  285.     byte*    desttop;
  286.     byte*    dest;
  287.     byte*    source; 
  288.     int        w; 
  289.     int        x0;
  290.      
  291.     y -= SWAPSHORT(patch->topoffset); 
  292.     x -= SWAPSHORT(patch->leftoffset); 
  293. #ifdef RANGECHECK 
  294.     if (x<0
  295.     ||x+SWAPSHORT(patch->width) >SCREENWIDTH
  296.     || y<0
  297.     || y+SWAPSHORT(patch->height)>SCREENHEIGHT 
  298.     || (unsigned)scrn>4)
  299.     {
  300.       fprintf( stderr, "Patch origin %d,%d exceeds LFB\n", x,y );
  301.       I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped");
  302.     }
  303. #endif 
  304.  
  305.     x0 = x;
  306.     col = 0; 
  307.     desttop = screens[scrn]+y*SCREENWIDTH+x; 
  308.      
  309.     w = SWAPSHORT(patch->width); 
  310.  
  311.     for ( ; col<w ; x++, col++, desttop++) 
  312.     { 
  313.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[w-1-col])); 
  314.  
  315.     // step through the posts in a column 
  316.     while (column->topdelta != 0xff ) 
  317.     { 
  318.         source = (byte *)column + 3; 
  319.         dest = desttop + column->topdelta*SCREENWIDTH; 
  320.         count = column->length; 
  321.              
  322.         while (count--) 
  323.         { 
  324.         *dest = *source++; 
  325.         dest += SCREENWIDTH; 
  326.         } 
  327.         column = (column_t *)(  (byte *)column + column->length 
  328.                     + 4 ); 
  329.     } 
  330.     }             
  331.     if (scrn == 0)
  332.     I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height));
  333.  
  334.  
  335.  
  336. #ifndef AMIGA
  337. //
  338. // V_DrawPatchDirect
  339. // Draws directly to the screen on the pc. 
  340. //
  341. void
  342. V_DrawPatchDirect
  343. ( int        x,
  344.   int        y,
  345.   int        scrn,
  346.   patch_t*    patch ) 
  347. {
  348.     V_DrawPatch (x,y,scrn, patch); 
  349. }
  350. #endif
  351.  
  352. void    //stretches bitmap to fill screen
  353. V_DrawPatchInDirect
  354. ( int        x,
  355.   int        y,
  356.   int        scrn,
  357.   patch_t*    patch    )
  358. {
  359.     int        count;
  360.     int        col; 
  361.     column_t*    column; 
  362.     byte*    desttop;
  363.     byte*    dest;
  364.     byte*    source; 
  365.     int        w; 
  366.     int        x0;
  367.  
  368.   int deltax,deltay,deltaxi,deltayi,stretchx,stretchy;
  369.   int srccol,collen;
  370.      
  371.   y -= SWAPSHORT(patch->topoffset); 
  372.   x -= SWAPSHORT(patch->leftoffset); 
  373.  
  374. #ifdef RANGECHECK 
  375.   if (x<0
  376.       ||x+SWAPSHORT(patch->width)>320
  377.       || y<0
  378.       || y+SWAPSHORT(patch->height)>200
  379.       || (unsigned)scrn>4)
  380.     {
  381.     fprintf(    stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  382.     // No I_Error abort - what is up with TNT.WAD?
  383.     fprintf(    stderr, "V_DrawPatch: bad patch (ignored)\n");
  384.     return;
  385.     }
  386. #endif 
  387.  
  388.   deltax=(SCREENWIDTH<<16)/320;
  389.   deltaxi=(320<<16)/SCREENWIDTH;
  390.   deltay=(SCREENHEIGHT<<16)/200;
  391.   deltayi=(200<<16)/SCREENHEIGHT;
  392.   stretchx=(x*deltax)>>16;
  393.   stretchy=(y*deltay)>>16;
  394.  
  395.   x0 = x;
  396.   col = 0;
  397.   desttop = screens[scrn]+stretchy*SCREENWIDTH+stretchx;
  398.      
  399.   w = SWAPSHORT(patch->width)<<16;
  400.  
  401.   for ( ; col < w; x++, col += deltaxi, desttop++) {
  402.     column = (column_t *)((byte *)patch + SWAPLONG(patch->columnofs[col>>16]));
  403.  
  404.     // step through the posts in a column
  405.     while    (column->topdelta    !=    0xff ) {
  406.       source = (byte *)column +    3;
  407.       dest = desttop+((column->topdelta*deltay)>>16)*SCREENWIDTH;
  408.       collen = count = (column->length*deltay)>>16;
  409.       srccol = 0;
  410.       while (count--) {
  411.         *dest = source[srccol>>16];
  412.         dest += SCREENWIDTH;
  413.         srccol += deltayi;
  414.       }
  415.       column = (column_t *)((byte *)column + (column->length)+4);
  416.     }
  417.   }
  418.   if (scrn == 0)
  419.       I_MarkRect (x0, y, SWAPSHORT(patch->width), SWAPSHORT(patch->height)); 
  420. }
  421.  
  422.  
  423. void    //stretches bitmap to fill screen
  424. V_DrawPatchInDirectFlipped
  425. ( int        x,
  426.   int        y,
  427.   int        scrn,
  428.   patch_t*    patch    )
  429.   {
  430.   int        count;
  431.   int        col;
  432.   column_t*    column;
  433.   byte*    desttop;
  434.   byte*    dest;
  435.   byte*    source;
  436.   int        w;
  437.  
  438.   int deltax,deltay,deltaxi,deltayi,stretchx,stretchy;
  439.   int srccol,collen;
  440.      
  441.   y    -=    SWAPSHORT(patch->topoffset);
  442.   x    -=    SWAPSHORT(patch->leftoffset);
  443. #ifdef RANGECHECK
  444.   if (x<0
  445.       ||x+SWAPSHORT(patch->width)    >320
  446.       ||    y<0
  447.       ||    y+SWAPSHORT(patch->height)>200
  448.       ||    (unsigned)scrn>4)
  449.   {
  450.     fprintf(    stderr, "Patch at %d,%d exceeds LFB\n", x,y );
  451.     // No I_Error abort - what is up with TNT.WAD?
  452.     fprintf(    stderr, "V_DrawPatch: bad patch (ignored)\n");
  453.     return;
  454.   }
  455. #endif 
  456.  
  457.   deltax=(SCREENWIDTH<<16)/320;
  458.   deltaxi=(320<<16)/SCREENWIDTH;
  459.   deltay=(SCREENHEIGHT<<16)/200;
  460.   deltayi=(200<<16)/SCREENHEIGHT;
  461.   stretchx=(x*deltax)>>16;
  462.   stretchy=(y*deltay)>>16;
  463.  
  464.   col = 0;
  465.   desttop    = screens[scrn]+stretchy*SCREENWIDTH+stretchx;
  466.  
  467.   w = SWAPSHORT(patch->width)<<16;
  468.  
  469.   for ( ; col < w; x++, col += deltaxi, desttop++) {
  470.     column = (column_t *)((byte *)patch    +
  471.                SWAPLONG(patch->columnofs[SWAPSHORT(patch->width)-1-(col>>16)]));
  472.  
  473.     // step through the posts in a column
  474.     while (column->topdelta != 0xff) {
  475.       source = (byte *)column +    3;
  476.       dest = desttop+((column->topdelta*deltay)>>16)*SCREENWIDTH;
  477.       collen = count = (column->length*deltay)>>16;
  478.       srccol=0;
  479.       while (count--) {
  480.         *dest=source[srccol>>16];
  481.         dest += SCREENWIDTH;
  482.         srccol+=deltayi;
  483.       }
  484.       column = (column_t *)((byte *)column+(column->length)+4);
  485.     }
  486.   }
  487.   if (scrn == 0)
  488.       I_MarkRect (stretchx,stretchy,(SWAPSHORT(patch->width)*deltax)>>16,
  489.                   (SWAPSHORT(patch->height)*deltax)>>16);
  490. }
  491.  
  492.  
  493.  
  494. //
  495. // V_DrawBlock
  496. // Draw a linear block of pixels into the view buffer.
  497. //
  498. void
  499. V_DrawBlock
  500. ( int        x,
  501.   int        y,
  502.   int        scrn,
  503.   int        width,
  504.   int        height,
  505.   byte*        src ) 
  506.     byte*    dest; 
  507.     int        height0;
  508.      
  509. #ifdef RANGECHECK 
  510.     if (x<0
  511.     ||x+width >SCREENWIDTH
  512.     || y<0
  513.     || y+height>SCREENHEIGHT 
  514.     || (unsigned)scrn>4 )
  515.     {
  516.     I_Error ("Bad V_DrawBlock");
  517.     }
  518. #endif 
  519.  
  520.     height0 = height;
  521.     dest = screens[scrn] + y*SCREENWIDTH+x; 
  522.  
  523.     while (height--) 
  524.     { 
  525.     memcpy (dest, src, width); 
  526.     src += width; 
  527.     dest += SCREENWIDTH; 
  528.     } 
  529.     if (scrn == 0)
  530.         I_MarkRect (x, y, width, height0);
  531. }
  532.  
  533.  
  534.  
  535. //
  536. // V_GetBlock
  537. // Gets a linear block of pixels from the view buffer.
  538. //
  539. void
  540. V_GetBlock
  541. ( int        x,
  542.   int        y,
  543.   int        scrn,
  544.   int        width,
  545.   int        height,
  546.   byte*        dest ) 
  547.     byte*    src; 
  548.      
  549. #ifdef RANGECHECK 
  550.     if (x<0
  551.     ||x+width >SCREENWIDTH
  552.     || y<0
  553.     || y+height>SCREENHEIGHT 
  554.     || (unsigned)scrn>4 )
  555.     {
  556.     I_Error ("Bad V_DrawBlock");
  557.     }
  558. #endif 
  559.  
  560.     src = screens[scrn] + y*SCREENWIDTH+x; 
  561.  
  562.     while (height--) 
  563.     { 
  564.     memcpy (dest, src, width); 
  565.     src += SCREENWIDTH; 
  566.     dest += width; 
  567.     } 
  568.  
  569.  
  570. #ifdef GRAFFITI
  571. extern int video_graffiti;
  572. #endif
  573.  
  574. //
  575. // V_Init
  576. // 
  577. void V_Init (void) 
  578.     int        i;
  579.     byte*    base;
  580.     int p;
  581.  
  582. #ifdef GRAFFITI
  583.     video_graffiti = 0;
  584.     if (M_CheckParm ("-graffiti")) {
  585.       video_graffiti = 1;
  586.       SCREENWIDTH = 320;
  587.       SCREENHEIGHT = 256;
  588.     } else if (M_CheckParm ("-graffiti2")) {
  589.       video_graffiti = 2;
  590.       SCREENWIDTH = 640;
  591.       SCREENHEIGHT = 256;
  592.     } else {
  593. #endif
  594.  
  595.       p = M_CheckParm ("-width");
  596.       if (p && p < myargc-1)
  597.         SCREENWIDTH = atoi(myargv[p+1]);
  598.       else
  599.         SCREENWIDTH = 320;
  600.  
  601.       p = M_CheckParm ("-height");
  602.       if (p && p < myargc-1)
  603.         SCREENHEIGHT = atoi(myargv[p+1]);
  604.       else
  605.         SCREENHEIGHT = 200;
  606.  
  607. #ifdef GRAFFITI
  608.     }
  609. #endif
  610.  
  611.     printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
  612.  
  613.     if (SCREENWIDTH < 320 || SCREENWIDTH > MAXSCREENWIDTH ||
  614.         SCREENWIDTH % 32 != 0 ||
  615.         SCREENHEIGHT < 200 || SCREENHEIGHT > MAXSCREENHEIGHT)
  616.       I_Error ("Resolution out of range or width is not a multiple of 32");
  617.  
  618.     if ((SCREENHEIGHT*8) == (SCREENWIDTH*5))
  619.       weirdaspect = 1;
  620.     else if ((SCREENHEIGHT*4) == (SCREENWIDTH*3))
  621.       weirdaspect = 0;
  622.     else {
  623.       weirdaspect = 0;
  624.       printf("Warning: Bad aspect ratio, things might look screwy\n");
  625.     }
  626.  
  627.     //allocate all the res-dependant vars
  628.     resinit_r_plane ();
  629.     resinit_am_map ();
  630.     resinit_r_draw ();
  631.     xtoviewangle = (angle_t *)I_calloc (SCREENWIDTH+1, sizeof(angle_t));
  632.     negonearray = (short *)I_calloc (SCREENWIDTH, sizeof(short));
  633.     screenheightarray = (short *)I_calloc (SCREENWIDTH, sizeof(short));
  634.  
  635.     // stick these in low dos memory on PCs
  636.  
  637.     base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT*4);
  638.  
  639.     for (i=0 ; i<4 ; i++)
  640.     screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
  641. }
  642.